/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Validation;

import entity.CustomerEntity;
import entity.SalesLeadEntity;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author sunwei
 */
public class SalesLeadCustomerSelectOneValidator implements Validator{

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
       
        SalesLeadEntity lead = (SalesLeadEntity) component.getAttributes().get("salesLead");

        
        CustomerEntity customer = (CustomerEntity) value;

        
        if (lead==null && customer==null ){
            throw new ValidatorException(new FacesMessage("SalesLead field and Customer field are both empty"));
        }
    }
    
}
